%{
#include <stdio.h>
#include<math.h>
%}
%union{
int i;
}
%token IF ELSE FOR WHILE DO RELOP ID
%type <i> S
%type <i> G 
%type <i> E
%type <i> C
%type <i> T
%type <i> F
%left '+' '-'
%left '*' '/'

%%
S : G S
  | I S 
  | G 
  | I 
;
I : IF '(' C ')' '\n' '{' '\n' S '\n' '}' {printf("'IF' statement found\n");}
  | ELSE '\n' '{' '\n' S '\n' '}' {printf("'ELSE' statement found\n");}
  | WHILE '(' C ')' '\n' '{' '\n' S '\n' '}' {printf("'WHILE' statement found\n");}
  | DO '\n' '{' '\n' S '\n' '}' WHILE '(' C ')' ';' {printf("'DO-WHILE' statement found\n");}
  | FOR '(' ';' C ';' ')' '\n' '{' '\n' S '\n' '}' {printf("'FOR' statement found\n");}
;
C : ID RELOP ID
;
G : ID '=' E ';'
  | ID '=' E {printf("ERROR : ':' missing\n");}
;
E : E '+' T
  | E '-' T
  | T
;
T : T '*' F
  | T '/' F
  | F
;
F : '(' E ')'
  | ID
;
%%

int yyerror(char *s)
{
	return 0;
}

int main()
{
	while(1)
		yyparse();
	return 0;	
}
